package com.alibaba.citrus.cr.price.ability.functions.factory.activity;

import com.alibaba.citrus.cr.price.repository.ActivityQueryRepository;
import com.alibaba.citrus.cr.common.util.SpringContextUtil;
import com.alibaba.citrus.cr.price.ability.functions.entity.activity.ActivityUseRecordRelationEntity;
import com.alibaba.cz.base.tool.log.Log;

import com.epoch.app.crpricecenter.dto.request.ActivityUseDetailQueryViewRequest;
import com.epoch.app.crpricecenter.dto.request.ParticipateActivityInfoRequest;
import com.epoch.app.crpricecenter.sdo.ActivityUseRecordRelationSDO;
import org.springframework.beans.BeanUtils;

/**
 * @author hanguo
 * @date 2021/10/18
 * @Description 活动使用工厂
 */
public class ActivityUseRecordRelationFactory {

    private static Log log = Log.getLogger(ActivityUseRecordRelationFactory.class);


    private static ActivityQueryRepository queryRepository = SpringContextUtil.getBean(ActivityQueryRepository.class);

    public static ActivityUseRecordRelationEntity create(ActivityUseDetailQueryViewRequest request) {

        ActivityUseRecordRelationSDO activityUseRecordRelationSDO = new ActivityUseRecordRelationSDO();
        BeanUtils.copyProperties(request, activityUseRecordRelationSDO);
        activityUseRecordRelationSDO.setStart(request.getStart());
        activityUseRecordRelationSDO.setLimit(request.getLimit());
        return ActivityUseRecordRelationEntity.of(activityUseRecordRelationSDO);
    }

    public static ActivityUseRecordRelationEntity create(ParticipateActivityInfoRequest request) {
//        //校验下参数
//        checkActivity(request);
        ActivityUseRecordRelationSDO activityUseRecordRelationSDO = queryRepository.queryActivityUseRecord(request);
        return ActivityUseRecordRelationEntity.of(activityUseRecordRelationSDO);
    }

//    private static void checkActivity(ParticipateActivityInfoRequest request) {
//        if(Objects.isNull(request)){
//            log.error("活动参数不能为空 = {}",request);
//            new RuntimeException("活动参数不能为空");
//        }
//
//
//        if(StringUtils.isBlank(request.getMainOrderId())){
//            log.error("参与活动的主订单编号不能为空 = {}",request);
//            new RuntimeException("参与活动的主订单编号不能为空");
//        }
//
//
//        if(StringUtils.isBlank(request.getSubOrderId())){
//            log.error("参与活动的子订单编号不能为空 = {}",request);
//            new RuntimeException("参与活动的子订单编号不能为空");
//        }
//
//
//        if(StringUtils.isBlank(request.getActivityId())){
//            log.error("活动编号不能为空 = {}",request);
//            new RuntimeException("活动编号不能为空");
//        }
//
//        if(Objects.isNull(request.getParticipateActivityTermRequest())){
//            log.error("活动项目不能为空 = {}",request);
//            new RuntimeException("活动项目不能为空");
//        }
//
//        if(StringUtils.isBlank(request.getParticipateActivityTermRequest().getActivityTermId())){
//            log.error("活动项目编号不能为空 = {}",request);
//            new RuntimeException("活动项目编号不能为空");
//        }
//
//        if(Objects.isNull(request.getParticipateActivityTermRequest().getItem())){
//            log.error("参与活动的商品参数不能为空 = {}",request);
//            new RuntimeException("参与活动的商品参数不能为空");
//        }
//
//        if(StringUtils.isBlank(request.getParticipateActivityTermRequest().getItem().getItemId())){
//            log.error("参与活动的商品编号不能为空 = {}",request);
//            new RuntimeException("参与活动的商品编号不能为空");
//        }
//
//        if (StringUtils.isBlank(request.getSequenceNo())) {
//            log.error("校验活动参数中的 SequenceNo不能为空，request={}", request);
//            throw new FacadeException("OTS-08-002-01-16-008");
//        }

//    }
}
